import React from 'react';
import { withRouter,Redirect } from 'react-router-dom';
import { connect } from 'react-redux';
import { loadData } from '../../redux/user.redux';

@withRouter
@connect(
state => state.user,
{ loadData }
)
class AuthRoute extends React.Component{
	componentDidMount(){
		const publicList  = ['/login','/register'];
		if (publicList.indexOf(this.props.location.pathname) > -1) {
			return null;
		}
		this.props.loadData();
	}
	
	render(){
		
		return (
		<div>
			{this.props.msg ? <Redirect to='/login'></Redirect> : null}
		</div>
		)
	}
}

export default AuthRoute;